// sample implementation
// based on PIC16F887

#include "Components/ampel.h"
#include "Components/control.h"
#include "Components/LightSignal.h"
#include "Components/LapCounter.h"

#define CYCLE_TIME 1000

uint_8 counter; // global counter
const uint_8 state_none = 0;


ISR timeloop()
{
	// setup timer for CYCLE_TIME...
	// save in counter!
}

void main(void)
{
	// initialize all components
	ampel_init();
	control_init();
	light_init();
	
	// configure components
	ampel_setCycle(CYCLE_TIME);
	lapcounter_setMax(5);
	
	// basic rules:
	// components may not know each other directly!
	// you just set the state of components
	while()
	{
		// start
		if(control_but1_pressed == control_getResult() ) // start of LAP-Counter Mode
		{
			ampel_start();
			light_start();
			lapcounter_start();
		}
		
		// reset
		if(control_but2_pressed == control_getResult() )
		{
			ampel_reset();
			light_reset();
			lapcounter_reset();
		}
		
		// runde ++
		if(light_s1_active == light_getResult() )
		{
			lapcounter_increment();
		}
		
		ampel_update(counter);
		control_update(counter); // wegen entprellen
		light_update(counter);
		lapcounter_update(counter); // wegen entprellen
	}
}